//const URL = 'http://127.0.0.1:90/webos/home/address/';
//const URL = 'http://192.168.1.183:8784/uaa/organization/';
const URL = developURL;
const DK = tongxunDK;
const  JK  = tongxunJK;
const ACCESS_TOKEN = localStorage.token ;

function apiCheckBranch(val){/*打开部门名片窗*/
	layer.open({
      type: 2,
      title: false,
      moveOut: true,
      closeBtn:1, //不显示关闭按钮
      maxmin: false,/*允许最大化*/
      shadeClose: true, //点击遮罩关闭层
      area : ['460px' , '590px'],
      content: './comptent/apiCheckBranch.html?val='+val,
    });
}


function apiCheckPerson(val){/*打开个人名片窗*/
	console.log(val);
	layer.open({
      type: 2,
      title: false,
      maxmin: false,/*允许最大化*/
      shadeClose: true, //点击遮罩关闭层
      area : ['460px' , '590px'],
      content: './comptent/apiCheckPerson.html?val='+val,
    });
}

function apiChooseBrance(ev,val){/*选中这个部门，更换数据*/
	ev.startLoading();
	return	axios({
	    method: 'post',
	    url: developURL+DK+JK+'selectByMyDept/'+val+'?'+'access_token='+ACCESS_TOKEN,
	})
	.then((res)=>{
		if(res.data.code=="S100101"){
			ev.rightBranchs = res.data.data.data;
			dealTopBranchs(ev.rightBranchs.myParent.data,ev);
//			console.log(ev.rightBranchs);
		
		}else{
			ev.throwErrors(res.data.msg);
		}
		ev.closeLoading();
	})
	.catch(function (error) {
	  console.log('网络出错',error);
	  ev.throwErrors('网络出错',error);
	})
}

function apiMountedLeft(ev){/*初始化 左边栏目*/
	ev.startLoading();
	return	axios({
	    method: 'post',
	    url: developURL+DK+JK+'selectByMyOrg?access_token='+ACCESS_TOKEN,
	})
	.then((res)=>{
		console.log(res);
		if(res.data.code=="S100101"){
			ev.branchsLeft=res.data.data.data;
		}else{
			ev.throwErrors(res.data.msg);
		}
		ev.closeLoading();
	})
	.catch(function (error) {
		console.log('网络出错',error);
	  	ev.throwErrors('网络出错',error);
	})
}

function apiSearch(ev,val){/*搜索设置*/
	
	if(ev.searchVal.length!=0){
			ev.startLoading();
			ev.isSearch=true;
			return axios({
			    method: 'post',
			    url: developURL+DK+JK+'searchByName?access_token='+ACCESS_TOKEN,
			    data:{
			    	name:ev.searchVal,
			    }
			})
			.then((res)=>{
				if(res.data.code=="S100101"){
					console.log(res);
					ev.searchLeft.person=res.data.data.data.userList;
					ev.searchLeft.branchs=res.data.data.data.organizationList;
				}else{
					ev.throwErrors(res.data.msg);
				}
				ev.closeLoading();
			})
			.catch(function (error) {
				console.log('网络出错',error);
			  	ev.throwErrors('网络出错',error);
			})
		}else{
			ev.isSearch=false;
	}
}

function apiBranchDetail(val,ev){/*部门名片内容*/
	ev.loadingPerson=layer.load(2);
	return	axios({
	    method: 'post',
	    url: developURL+DK+JK+'getMyDept/'+val+'?'+'access_token='+ACCESS_TOKEN,
	})
	.then((res)=>{
		if(res.data.code=="S100101"){
			console.log(res);
			ev.branchTitle = res.data.data.data.currDept.name;
			if(res.data.data.data.parentDept!=undefined){
				ev.branchDetail.upBranch =res.data.data.data.parentDept.name;
			}else{
				ev.branchDetail.upBranch =null;
			}
			ev.branchDetail.officePhone=res.data.data.data.currDept.telephone;
		}else{
			alert(res.data.msg);
		}
		layer.close(ev.loadingPerson)
	})
	.catch(function (error) {
	  console.log('网络出错',error);
	})
}


function apiPersonDetail(val,ev){/*查询人的详细内容*/
	ev.loadingPerson=layer.load(2);
	return	axios({
	    method: 'post',
	    url: developURL+DK+JK+'getPersionCard/'+val+'?'+'access_token='+ACCESS_TOKEN,
	})
	.then((res)=>{
		if(res.data.code=="S100101"){
			console.log(res);
			ev.policeDetail = res.data.data.data;
//			if(ev.policeDetail.picture.indexOf('http')===-1){/*没有图片*//*肇庆市那边的系统，连这个字段都没有传来，不能用indexof，*/
//				ev.policeDetail.picture = ev.policeDetail.name.charAt(ev.policeDetail.name.length-1);
//			}
//			console.log(ev.policeDetail);
		}else{
			alert(res.data.msg);
		}
		layer.close(ev.loadingPerson)
	})
	.catch(function (error) {
	  console.log('网络出错',error);
	})
	
}

let arr = [];
function dealTopBranchs(parent,ev){/*递归，排成数组，右上角显示*/
	arr.push(parent);
	if(parent.organizationVos!=undefined){
		dealTopBranchs(parent.organizationVos[0],ev);
	}else{
		ev.topBranchs =arr;
		arr = [];
		return ;
	}
}

function getParam(paramName){/*根据参数获取数据*/
			  		paramValue =""; 
						  isFound =false; 
						  if (this.location.search.indexOf("?") ==0&&this.location.search.indexOf("=")>1){ 
						    arrSource = unescape(this.location.search).substring(1,this.location.search.length).split("&"); 
						    i =0; 
						    while (i < arrSource.length &&!isFound){ 
						      if (arrSource[i].indexOf("=") >0){ 
						        if (arrSource[i].split("=")[0].toLowerCase()==paramName.toLowerCase()){ 
						          paramValue = arrSource[i].split("=")[1]; 
						          isFound =true; 
						        } 
						      } 
						    i++; 
						    } 
						  } 
	    			return paramValue;
}

